package com.jianhua.appmarket.common.config;

import com.jianhua.appmarket.common.util.JWTUtil;
import com.jianhua.appmarket.module.entity.system.User;
import com.jianhua.appmarket.module.model.system.UserVO;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebArgumentResolver;
import org.springframework.web.context.request.NativeWebRequest;

import javax.servlet.http.HttpServletRequest;


public class UserWebArgumentResolver implements WebArgumentResolver {

    @Override
    public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest nativeWebRequest) {
        if(methodParameter.getParameterType().equals(UserVO.class)){
            HttpServletRequest request = nativeWebRequest.getNativeRequest(HttpServletRequest.class);
            return JWTUtil.getUser(request.getHeader("token"));
        }
        return UNRESOLVED;
    }
}
